package com.ruoyi.hqfinance.service.impl;

import com.github.pagehelper.PageHelper;
import com.ruoyi.hqfinance.domain.*;
import com.ruoyi.hqfinance.domain.vo.HqInformStandardSheetVo;
import com.ruoyi.hqfinance.domain.vo.HqInformStandardVo;
import com.ruoyi.hqfinance.mapper.*;
import com.ruoyi.hqfinance.service.HqInformStandardService;
import com.ruoyi.qualityControl.utils.GetDate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class HqInformStandardServiceImpl implements HqInformStandardService {
    @Autowired
    private HqInformStandardSheetMapper hqInformStandardSheetMapper;
    @Autowired
    private HqInformStandardSignTypeMapper hqInformStandardSignTypeMapper;
    @Autowired
    private HqInformStandardPlatformMapper hqInformStandardPlatformMapper;
    @Autowired
    private HqInformStandardEndInformMapper hqInformStandardEndInformMapper;
    @Autowired
    private HqInformStandardEndSevenDataMapper hqInformStandardEndSevenDataMapper;
    private List<String> sevenDate = GetDate.getSevenDate();

    @Override
    public List<HqInformStandardSheet> sheetCollect(HqInformStandardSheetVo vo) {
        PageHelper.startPage(vo.getPageDate());
        List<HqInformStandardSheet> sheets = hqInformStandardSheetMapper.sheetCollect(vo);
        assert sheets != null;
        for (HqInformStandardSheet sheet : sheets) {
            sheet.setCallRate(sheet.getCallRate() + "%");
            sheet.setSmsRate(sheet.getSmsRate() + "%");
            sheet.setCallTaggedPerformanceRate(sheet.getCallTaggedPerformanceRate() + "%");
            sheet.setSmsTaggedNotificationRate(sheet.getSmsTaggedNotificationRate() + "%");
            if (vo.getTimeType() == 2) {
                sheet.setDate(vo.getStartTime() + "至" + vo.getEndTime());
            }
        }
        return sheets;
    }

    @Override
    public List<HqInformStandardSignType> collectSignType(HqInformStandardVo vo) {
        List<HqInformStandardSignType> sheets = hqInformStandardSignTypeMapper.collectSignType(vo);
        assert sheets != null;
        for (HqInformStandardSignType sheet : sheets) {
            sheet.setCallRate(sheet.getCallRate() + "%");
            sheet.setSmsRate(sheet.getSmsRate() + "%");
            if (vo.getTimeType() == 2) {
                sheet.setDate(vo.getStartTime() + "至" + vo.getEndTime());
            }
        }
        return sheets;
    }

    @Override
    public List<HqInformStandardPlatform> collectPlatform(HqInformStandardVo vo) {
        List<HqInformStandardPlatform> sheets = hqInformStandardPlatformMapper.collectPlatform(vo);
        assert sheets != null;
        for (HqInformStandardPlatform sheet : sheets) {
            sheet.setCallRate(sheet.getCallRate() + "%");
            sheet.setSmsRate(sheet.getSmsRate() + "%");
            sheet.setCallTaggedPerformanceRate(sheet.getCallTaggedPerformanceRate() + "%");
            sheet.setSmsTaggedNotificationRate(sheet.getSmsTaggedNotificationRate() + "%");
            if (vo.getTimeType() == 2) {
                sheet.setDate(vo.getStartTime() + "至" + vo.getEndTime());
            }
        }
        return sheets;
    }

    @Override
    public HqInformStandardEndInform collectEndInform(HqInformStandardVo vo) {
        return hqInformStandardEndInformMapper.collectEndInform(vo);
    }

    @Override
    public List<HqInformStandardEnd> endInform(HqInformStandardVo vo) {
        List<HqInformStandardEnd> ends = new ArrayList<>();
        HqInformStandardEndInform inform = hqInformStandardEndInformMapper.collectEndInform(vo);
        ends.add(new HqInformStandardEnd(inform.getReceiptVolume(), inform.getCallVolume(), inform.getCallRate(), null, null, null, null, null, null, null, null, null, callSeven(sevenDate)));
        ends.add(new HqInformStandardEnd(null, null, null, inform.getSmsVolume(), inform.getSmsRate(), inform.getReceiptVolume(), null, null, null, null, null, null, smsSeven(sevenDate)));
        ends.add(new HqInformStandardEnd(null, null, null, null, null, null, inform.getCallTaggedVolume(), inform.getCallTaggedPerformedVolume(), inform.getSmsTaggedNotificationRate(), null, null, null, callTaggedSeven(sevenDate)));
        ends.add(new HqInformStandardEnd(null, null, null, null, null, null, null, null, null, inform.getSmsTaggedRate(), inform.getSmsTaggedNum(), inform.getSmsInformNum(), smsTaggedSeven(sevenDate)));
        return ends;
    }

    @Override
    public List<HqInformStandardEndSevenData> callSeven(List<String> date) {
        List<HqInformStandardEndSevenData> sevens = hqInformStandardEndSevenDataMapper.callSeven(sevenDate);
        List<HqInformStandardEndSevenData> list = new ArrayList<>();
        for (int i = 0; i < sevenDate.size(); i++) {
            HqInformStandardEndSevenData seven = new HqInformStandardEndSevenData();
            seven.setCollectDate(sevenDate.get(i));
            boolean bool = false;
            for (int m = 0; m < sevens.size(); m++) {
                if (sevenDate.get(i).equals(sevens.get(m).getCollectDate())) {
                    seven.setRate(sevens.get(m).getRate());
                    bool = true;
                    break;
                }
            }
            if (!bool) {
                seven.setRate("0");
            }
            list.add(seven);
        }
        return list;
    }

    @Override
    public List<HqInformStandardEndSevenData> smsSeven(List<String> date) {
        List<HqInformStandardEndSevenData> sevens = hqInformStandardEndSevenDataMapper.smsSeven(sevenDate);
        List<HqInformStandardEndSevenData> list = new ArrayList<>();
        for (int i = 0; i < sevenDate.size(); i++) {
            HqInformStandardEndSevenData seven = new HqInformStandardEndSevenData();
            seven.setCollectDate(sevenDate.get(i));
            boolean bool = false;
            for (int m = 0; m < sevens.size(); m++) {
                if (sevenDate.get(i).equals(sevens.get(m).getCollectDate())) {
                    seven.setRate(sevens.get(m).getRate());
                    bool = true;
                    break;
                }
            }
            if (!bool) {
                seven.setRate("0");
            }
            list.add(seven);
        }
        return list;
    }

    @Override
    public List<HqInformStandardEndSevenData> callTaggedSeven(List<String> date) {
        List<HqInformStandardEndSevenData> sevens = hqInformStandardEndSevenDataMapper.callTaggedSeven(sevenDate);
        List<HqInformStandardEndSevenData> list = new ArrayList<>();
        for (int i = 0; i < sevenDate.size(); i++) {
            HqInformStandardEndSevenData seven = new HqInformStandardEndSevenData();
            seven.setCollectDate(sevenDate.get(i));
            boolean bool = false;
            for (int m = 0; m < sevens.size(); m++) {
                if (sevenDate.get(i).equals(sevens.get(m).getCollectDate())) {
                    seven.setRate(sevens.get(m).getRate());
                    bool = true;
                    break;
                }
            }
            if (!bool) {
                seven.setRate("0");
            }
            list.add(seven);
        }
        return list;
    }

    @Override
    public List<HqInformStandardEndSevenData> smsTaggedSeven(List<String> date) {
        List<HqInformStandardEndSevenData> sevens = hqInformStandardEndSevenDataMapper.smsTaggedSeven(sevenDate);
        List<HqInformStandardEndSevenData> list = new ArrayList<>();
        for (int i = 0; i < sevenDate.size(); i++) {
            HqInformStandardEndSevenData seven = new HqInformStandardEndSevenData();
            seven.setCollectDate(sevenDate.get(i));
            boolean bool = false;
            for (int m = 0; m < sevens.size(); m++) {
                if (sevenDate.get(i).equals(sevens.get(m).getCollectDate())) {
                    seven.setRate(sevens.get(m).getRate());
                    bool = true;
                    break;
                }
            }
            if (!bool) {
                seven.setRate("0");
            }
            list.add(seven);
        }
        return list;
    }
}
